package com.bop.dehong.decaifu.fragment;

import android.text.Html;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.base.dehong.http.RequestCallBack;
import com.base.dehong.util.ToastUtils;
import com.bop.dehong.R;
import com.bop.dehong.base.BaseFragment;
import com.bop.dehong.base.DeHongApp;
import com.bop.dehong.config.Config;
import com.bop.dehong.decaifu.adapter.AuditImgtAdapter;
import com.bop.dehong.http.model.ToubiaoAuditModel;
import com.bop.dehong.info.entity.RiskauditItemEntity;
import com.bop.dehong.info.entity.ToubiaoRiskauditEntity;

public class Riskaudit extends BaseFragment {
  private TextView audit_info;
  private ListView listView;
  private AuditImgtAdapter auditImgtAdapter;
  private ToubiaoAuditModel toubiaoAuditModel;
  private String id, uid;
  private RiskauditItemEntity entity;
  
	@Override
	protected void initTop() {
		mPageName = getClass().getName();
	}

	@Override
	protected void initUI() {
		audit_info = getView(R.id.audit_info);
		listView = getView(R.id.list_img);
		id = getActivity().getIntent().getExtras().getString(Config.CAT_ID);
		if (auditImgtAdapter == null)
		{
			auditImgtAdapter = new AuditImgtAdapter(getActivity());
		}
		listView.setAdapter(auditImgtAdapter);
	}

	@Override
	public void initData() {
		if (DeHongApp.mLoginEntity != null) {
			uid = DeHongApp.mLoginEntity.getUid();
		}else {
			ToastUtils.show(getActivity(), "还未登录，请先登录再查询风控审核！");
			return;
		}
		if (entity != null) {
			CharSequence charSequence = Html.fromHtml(entity.getRisk_control());  
			audit_info.setText(charSequence);
//			auditImgtAdapter.appendToList(entity.thumb);
		}else{
			showProgressDialog();
			if (toubiaoAuditModel == null) {
				toubiaoAuditModel = new ToubiaoAuditModel(getActivity(), callback);
			}
			toubiaoAuditModel.doNet(id, uid);
		}
	}

	RequestCallBack<ToubiaoRiskauditEntity> callback = new RequestCallBack<ToubiaoRiskauditEntity>() {

		@Override
		public void end() {
			disappearProgressDialog();
		}
		
		public void onSuccess(ToubiaoRiskauditEntity info) {
			entity = info.getItem();
			CharSequence charSequence = Html.fromHtml(entity.getRisk_control());  
			audit_info.setText(charSequence);
			auditImgtAdapter.appendToList(info.getItem().thumb);
			super.onSuccess(info);
		};
		
	};
	
	
	@Override
	protected int getContentViewId() {
		return R.layout.fragment_riskaudit;
	}


	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id)
	{
		// TODO Auto-generated method stub
		
	}

}
